from ultralytics import YOLO
# 加载模型
# model = YOLO("runs/detect/train21/weights/best_modified.pt")  # 推荐加载预训练权重
model = YOLO("runs/detect/train16/weights/best.pt")  # 推荐加载预训练权重
if __name__ == '__main__':
    # 训练配置
    results = model.train(
        data="ultralytics/cfg/datasets/helmet4.yaml",
        epochs=30,
        freeze=[0, 1, 2, 3, 4, 5],   # 冻结前N层参数
        lr0=0.0001,  # 减小学习率防止破坏原有权重
        pretrained=True,
        batch=48,
        imgsz=640,
        device=0,
        project="runs/detect",
        workers=0  # 关键！Windows下禁用多进程数据加载
    )

# yolo task=detect mode=train model=weights/yolov8n.pt data=ultralytics/cfg/datasets/CCPD-test.yaml batch=16 epochs=50 imgsz=416 workers=1 device=0 project=runs/detect